package com.itcast.demo_one.kotlin

fun main() {
    // println(ifFunc(1100, 200))

    // println(whenFunc(3))
    // println(getGrade(91))
//    println(getGrade2(80))
    println(getGrade3(101))
}

// 1. if语句
fun ifFunc(num1: Int, num2: Int): Int {
    // 写法1:
    return if(num1 > num2){
        num1
    } else {
        num2
    }

    // 写法2:
    // return if (num1 > num2) num1 else num2
}

// 2. when语句
fun whenFunc(num: Int): String {
    return when(num) {
        1 -> "one"
        2 -> "two"
        3 -> "three"
        else -> "other"
    }
}

// 根据成绩输出等级
fun getGrade(score: Int): String {
    return when {
        score >= 90 -> "A"
        score >= 80 -> "B"
        score >= 70 -> "C"
        score >= 60 -> "D"
        else -> "E"
    }
}

// 根据成绩输出等级 第二种写法 用 in
fun getGrade2(score: Int): String {
    return when(score) {
        in 90..100 -> "A"
        in 80..89 -> "B"
        in 70..79 -> "C"
        in 60..69 -> "D"
        else -> "E"
    }
}

// 根据成绩输出等级 第二种写法 用 in 和 until
fun getGrade3(score: Int): String  = when(score) {
    in 90 until 101 -> "A"
    in 80  until 90 -> "B"
    in 70 until 80 -> "C"
    in 60 until 70 -> "D"
    else -> "E"
}
